package com.yc.chaoshi.cs_manage.controller;



import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.chaoshi.cs_manage.mapper.PmsBrandMapper;
import com.yc.chaoshi.entity.PmsBrand;

import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xz
 * @since 2022-08-04
 */
@RestController
@RequestMapping("/chaoshi/pmsBrand")
public class PmsBrandController {
    //                     /chaoshi/pmsFenlei1/selectFenlei1
    //http://127.0.0.1:8004/chaoshi/pmsFennlei1/selectFenlei1
    @Resource
    private PmsBrandMapper brandMapper;

    @RequestMapping("selectbrand")
    public Page selectbrand(@RequestParam(defaultValue = "") String pname,
                              @RequestParam(defaultValue = "1") int page){
        Page<PmsBrand> ipage = new Page<>(page,10);
        ipage.orders().add(OrderItem.asc("pid"));
        System.out.println(brandMapper.selectbrand(pname, (page - 1) * 10,10));
        ipage.setRecords(brandMapper.selectbrand(pname, (page - 1) * 10,10));
        System.out.println(brandMapper.selectbrand(pname,0,1000).size());
        long total = brandMapper.selectbrand(pname,0,10000).size();
        ipage.setTotal(total);
        return ipage;
    }

    @GetMapping("updateBrand")
    public int updateBrand(@RequestParam String pname,
                           @RequestParam String pmsg,
                           @RequestParam int display,
                           @RequestParam int pid) {
        brandMapper.updateBrand(pname,pmsg,display,pid);
        return 0;
    }

    @GetMapping("deleteBrand")
    public int deleteBrand(@RequestParam int pid ){
        brandMapper.deleteBrand(pid);
        return 0;
    }

    @GetMapping("insertBrand")
    public int insertGoods(@RequestParam String pname,
                           @RequestParam String pmsg,
                           @RequestParam int display){
        brandMapper.insertBrand(pname,pmsg,display);
        return 0;
    }
}

